<?php

namespace Home\Controller;

use Think\Controller;

class DemoController extends BaseController {
	/**
	 * test
	 * */
	public function queryPacketList() {
		$data = array('stationId' => 366, 'packetType' => '-250','mobile' => I('mobile'));

		if (empty($data['stationId']) || $data['packetType'] == '') {
			$this->param_error();
		}
		if (empty($data['mobile'])) {
			$data['mobile'] = '';
		}

		//时间筛选为空、通知中和通知失败的时候默认搜索两个月的数据
		//防止出现每月一号数据异常
		if (empty($data['beginDate']) || $data['packetType'] == 2 || $data['packetType'] == 5) {

			$startTime = date('Y-m-01', strtotime("-1 month"));
			$endTime = date('Y-m-d');
		}

		$mobile = $mailNO = '';

		//运单号搜索  2017-05-08
		if (preg_match('/^[1][34578]\d{9}$/', $data['mobile'])) {
			$mobile = $data['mobile'];
		} else {
			$mailNO = $data['mobile'];
		}


		$parcelService = new \Home\Server\ParcelService();
		//总数量
		$count = $parcelService->countConditionStorage($data['stationId'], $mobile, $data['beginDate'], $data['packetType'], $data['fCompanyId'], $mailNO, '', $startTime, $endTime);

		//查询通知中和通知失败的数据
		//通知中、通知失败结果不受条件限制
		$noticeIng = $parcelService->countConditionStorage($data['stationId'], 0, '', 2, '', '', '', date('Y-m-01', strtotime("-1 month")), date('Y-m-d'));
		$noticeFail = $parcelService->countConditionStorage($data['stationId'], 0, '', 5, '', '', '', date('Y-m-01', strtotime("-1 month")), date('Y-m-d'));

		$page = !empty($data['currentPage']) ? $data['currentPage'] : 1;

		//兼容错误的APP参数
		if (strpos($data['currentPage'], 'Optional') !== False) {
			$page = substr($data['currentPage'], 9, -1);
		}

		$pageSize = !empty($data['pageSize']) ? $data['pageSize'] : 20;
		$totalPages = ceil($count / $pageSize);

		//查询数据
		$packetList = $parcelService->getConditionStorage($data['stationId'], $mobile, $data['beginDate'], $data['packetType'], $page, $pageSize, $data['fCompanyId'], $mailNO, '', $startTime, $endTime);

		$noticeIng == false ? $noticeIng = '0' : $noticeIng;
		$noticeFail == false ? $noticeFail = '0' : $noticeFail;

		$result = array(
			'count' => $count,
			'noticeIng' => $noticeIng,
			'noticeFail' => $noticeFail,
			'pcketinfo' => $packetList,
			'totlePage' => $totalPages
		);
		$this->output(true, $result);
	}


	public function weixin_notice(){
		//发微信并记录发送微信次数，根据返回值修改微信通知状态或成功发送时间
		$data = array(
			'mobile'    => '18602551320', //收件人手机号码
			'name'      => '悠谷',     //站点名称
			'mailno'    => '88888888',                  //运单号
			'code'      => '88888',                //提货码
			'company'   => '熊猫快递',     //快递公司名称
			'address'   => '中国南京',          //站点地址
			'qtime'     => '全年无休',            //站点营业时间
			'remark'    => '感谢您的使用',
			'type'      => 0,     //入库类型  0.普通版  1.专业版  2.极速版  2017-5-23 quyang
			'tel'       => '025-88888888'               //站点的联系电话
		);
		$return_weixin = send_weixin($data);
		dump($return_weixin);
	}

}
